#ifndef _PACKET_H_
#define _PACKET_H_

#include "ds18b20_temp.h"

#define DEVSN_LEN 10

typedef struct packet_s
{
	float			temp; /* temperature */
	char			time[32]; /* date/time: YYYY-MM-DD hh:mm:ss */
	char			devsn[DEVSN_LEN+1]; /* SN format: RPI2304001 */
} packet_t;

/* Description: Get device serial number */
int get_devsn(char *devsn, int size);

/* Description: Get date/time */
int get_time(char *time, int size);

static inline int sample_temperature(packet_t *pack)
{
	if( !pack )
	{
		return -1;
	}
	memset(pack, 0, sizeof(*pack));
	if( get_temp(&pack->temp) )
	{
		return -2;
	}
	get_time(pack->time, sizeof(pack->time));
	get_devsn(pack->devsn, DEVSN_LEN+1);
	return 0;
}

/* Description: Convert data from $pack to string format and save in $buf
   String Format: "RPI2304001,2023-04-13 20:08:08,26.66"
   */
int pack_data(packet_t *pack, char *buf, int size);

#endif   /* ----- #ifndef _PACKET_H_  ----- */
